package com.sky.controller.user;

import cn.hutool.core.bean.BeanUtil;
import com.sky.constant.StatusConstant;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishOverViewVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/user/setmeal")
@RestController("userSetmealController")
@Api(tags = "C端-套餐相关接口")
@RequiredArgsConstructor
@Slf4j
public class SetmealController {

    private final SetmealService setmealService;

    private final DishService dishService;

    /**
     * 根据分类id获取套餐
     * @param categoryId
     * @return
     */
    @ApiOperation("根据分类id获取套餐")
    @GetMapping("/list")
    @Cacheable(cacheNames = "sky:setmeal",key = "#categoryId")
    public Result<List<Setmeal>> list(Long categoryId) {
        log.info("获取分类为{}的套餐",categoryId);
        List<Setmeal> setmealList = setmealService.getByCategory(categoryId);
        return Result.success(setmealList);
    }

    /**
     * 根据套餐id查询包含的菜品
     * @param id
     * @return
     */
    @ApiOperation("根据套餐id查询包含的菜品")
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> getBySetmealId(@PathVariable Long id) {
        log.info("套餐id为{}的所有菜品",id);
        List<DishItemVO> dishItemVOList = dishService.getDishItem(id);
        System.out.println("dishItemVOList = " + dishItemVOList);
        return Result.success(dishItemVOList);
    }
}
